package com.foxchen.decrypt.service;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@Slf4j
public class DbInitCheckService {
    private final DataSource dataSource;

    public DbInitCheckService(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @PostConstruct
    public void init() throws SQLException {
        this.isReady();
    }

    public void isReady() throws SQLException {
        try (Connection conn = this.dataSource.getConnection()) {
            conn.isValid(5000);
            log.info("============dataSource check over and it's ready============");
        }
    }
}
